<?php
require_once FRAMEWORK_PATH . 'View' . DIRECTORY_SEPARATOR . 'TemplateEngine' . DIRECTORY_SEPARATOR . 'serpent' . DIRECTORY_SEPARATOR . 'serpent.class.php';

class View_Serpent implements View_Interface {
    
    /**
     * @var serpent
     */
    private $_templateEngine;
    
    public function __construct ($config = array()) {
        $this->_templateEngine = new Serpent();
        $this->_templateEngine->compile_dir = APP_PATH . 'view' . DIRECTORY_SEPARATOR . 'template_c';
        $this->_templateEngine->force_compile = false;
        $this->_templateEngine->autoescape = false;
        $this->_templateEngine->default_resource = 'file';
        $this->_templateEngine->default_compiler = 'serpent';
        $this->_templateEngine->setCharset('utf-8');
        
        $default = array(
            'template_dir' => APP_PATH . 'view' , 
            'suffix' => '.html' , 
            'language' => 'cn');
        
        $config = array_merge($default, $config);
        $this->_templateEngine->addPluginConfig('resource', 'file', $config);
    }
    
    public function assign (array $data) {
        $this->_templateEngine->pass($data);
    }
    
    public function display ($tpl) {
		echo $this->_templateEngine->render($tpl);
    }
}
?>